package websocket;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class AnalyzeJson {
	public LogInStruct AnalyzeLogin(JSONObject jsonObject) throws JSONException
	{
		LogInStruct login = new LogInStruct();
		
		
		JSONObject result = jsonObject.getJSONObject("result");
		login.result.message = result.optString("message");
		login.result.statusCode = result.optString("statusCode");
		
		JSONObject data;
		try {
			data = jsonObject.getJSONObject("data");
			login.data.cardSize = data.optInt("cardSize");
		}
		catch(JSONException e) {
			// TODO Auto-generated catch block
			login.data = null;
			e.printStackTrace();
			return login;
		}
		
		try {
			JSONObject confirmInvitationResult = data.getJSONObject("confirmInvitationResult");
			login.data.confirmInvitationResult.message = confirmInvitationResult.optString("message");
			login.data.confirmInvitationResult.statusCode = confirmInvitationResult.optString("statusCode");
		}
		catch(JSONException e) {
			// TODO Auto-generated catch block
			login.data.confirmInvitationResult = null;
			e.printStackTrace();
		}
		JSONObject course = data.getJSONObject("course");
		login.data.course.capacity = course.optInt("capacity");
		login.data.course.description = course.optString("description");
		login.data.course.maxSheetCards = course.optInt("capacity");
		login.data.course.maxSheetMembers = course.optInt("maxSheetMembers");
		login.data.course.maxSheets = course.optInt("maxSheets");
		login.data.course.name = course.optString("name");
		
		login.data.currentCapacity = data.optInt("currentCapacity");
		login.data.fbId = data.optString("fbId");
		login.data.isPwdSetted = data.optString("isPwdSetted");
		login.data.locale = data.optString("locale");
		login.data.sessionId = data.optString("sessionId");
		login.data.tokenId = data.optString("tokenId");
		login.data.userConfig = data.optString("userConfig");
		login.data.userId = data.optInt("userId");
		login.data.userName = data.optString("userName");
		
		return login;
	}
}
